package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.EmailBean;
import com.project.bean.EmployeeBean;
import com.project.bean.InboxBean;
import com.project.service.IInboxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@RestController
@RequestMapping("inbox")
public class InboxController {
    @Autowired
    private IInboxService service;
    @RequestMapping("findByItem")
    public IPage<InboxBean> findByItem(Integer pageNO,
                                       String head,
                                       LocalDate startDate,
                                       LocalDate endDate,
                                       HttpServletRequest req) {

        EmployeeBean loginUser = (EmployeeBean) req.getSession().getAttribute("loginUser");

        return service.cutByItem(pageNO, loginUser.getEmId(), head, startDate, endDate);
    }

    @RequestMapping("findById")
    public EmailBean findById(Integer inboxId) {
        return service.findById(inboxId);
    }

    @RequestMapping("del")
    public String del(Integer inboxId) {
        service.del(inboxId);
        return "ok";
    }
}
